package com.paas.form.controller;


import com.paas.form.entity.FormDefinitionEntity;
import com.paas.form.service.IFormDefinitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.text.ParseException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.paas.common.util.BeanUtil;
import com.paas.common.web.annotion.OperLog;
import com.paas.common.web.controller.BaseController;
import com.paas.common.web.oper.OprLogConstant;


import com.paas.form.entity.FormViewPublishApprovalEntity;
import com.paas.form.service.IFormViewPublishApprovalService;

@RestController
@RequestMapping(value = "/form/formViewPublishApproval")
@Api(description = "视图模块", tags = "")
public class FormViewPublishApprovalController extends BaseController {

    @Autowired
    public IFormViewPublishApprovalService formViewPublishApprovalService;

    @Autowired
    public IFormDefinitionService formViewPublishService;

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @OperLog(operType = OprLogConstant.ADD,operModul = "",operDescribe = "-保存")
    public void save(@RequestBody FormViewPublishApprovalEntity formViewPublishApprovalEntity) throws ParseException{
		if(BeanUtil.isNotEmpty(formViewPublishApprovalEntity)){
			injectUpdateDataAuth(formViewPublishApprovalEntity);
		}
    	formViewPublishApprovalService.save(formViewPublishApprovalEntity);
    }

    @RequestMapping(value = "/saveBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量保存信息", notes = "批量保存信息")
    @OperLog(operType = OprLogConstant.UPDATE,operModul = "",operDescribe = "-批量保存修改")
    public void saveBatch(@RequestBody List<FormViewPublishApprovalEntity> list) throws ParseException{
		if(list!=null && list.size()>0){
            injectUpdateDataAuth(list);
        }
    	formViewPublishApprovalService.saveBatch(list);
    }

    @RequestMapping(value = "/delectById",method = RequestMethod.GET)
    @ApiOperation(value = "根据Id删除数据", notes = "根据Id删除数据")
    @OperLog(operType = OprLogConstant.DELETE,operModul = "",operDescribe = "-删除")
    public void delectById(String id){
		if (null != id && !"".equals(id)) {
			FormViewPublishApprovalEntity formViewPublishApprovalEntity = new FormViewPublishApprovalEntity();
			injectUpdateDataAuth(formViewPublishApprovalEntity);
			formViewPublishApprovalEntity.setId(id);
			formViewPublishApprovalService.deleteByEntity(formViewPublishApprovalEntity);
		}
    }

    @RequestMapping(value = "/deleteBatchByIds",method = RequestMethod.POST)
    @ApiOperation(value = "根据Id批量删除数据", notes = "根据Id批量删除数据")
    @OperLog(operType = OprLogConstant.DELETE,operModul = "",operDescribe = "-批量删除")
    public void deleteBatchByIds(@RequestBody List<String> ids){
		if (null != ids && ids.size() > 0) {
			FormViewPublishApprovalEntity formViewPublishApprovalEntity = new FormViewPublishApprovalEntity();
			injectUpdateDataAuth(formViewPublishApprovalEntity);
			//formViewPublishApprovalService.deleteBatchIds(ids);
			formViewPublishApprovalService.deleteBatchIdsWithPermission(ids,formViewPublishApprovalEntity);
		}
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询对象", notes = "根据Id查询对象")
    public FormViewPublishApprovalEntity queryById(String id){
         FormViewPublishApprovalEntity bean = formViewPublishApprovalService.getById(id);
         return bean;
    }

    @RequestMapping(value = "/queryBatchByIds",method = RequestMethod.POST)
    @ApiOperation(value = "根据Id查询对象列表", notes = "根据Id查询对象列表")
    public List<FormViewPublishApprovalEntity> queryBatchByIds(@RequestBody List<String> ids){
         List<FormViewPublishApprovalEntity> list = formViewPublishApprovalService.getBatchByIds(ids);
         return list ;
    }

    @RequestMapping(value = "/queryPage",method = RequestMethod.GET)
    @ApiOperation(value = "模板分页查询", notes = "模板分页查询")
    public IPage<FormViewPublishApprovalEntity> queryPage(FormViewPublishApprovalEntity formViewPublishApprovalEntity, Integer currentPage, Integer pageSize){
    	if (currentPage == null) {
    		currentPage = 1;
    	}
    	if (pageSize == null) {
    		pageSize = 10;
    	}
		injectCheckDataAuth(formViewPublishApprovalEntity);
    	IPage<FormViewPublishApprovalEntity> pageBean = formViewPublishApprovalService.getPage(formViewPublishApprovalEntity, currentPage, pageSize);
        List<FormViewPublishApprovalEntity> list = pageBean.getRecords();
    	return pageBean;
    }

    @RequestMapping(value = "/queryList",method = RequestMethod.GET)
    @ApiOperation(value = "模板查询", notes = "模板查询")
    public List<FormViewPublishApprovalEntity> queryList(FormViewPublishApprovalEntity formViewPublishApprovalEntity){
		injectCheckDataAuth(formViewPublishApprovalEntity);
    	List<FormViewPublishApprovalEntity> list = formViewPublishApprovalService.getList(formViewPublishApprovalEntity);
        return list;
    }
}